#include "../../head.h"

// 消息队列是IPC对象 使用之前需要获取key值

struct msgbuf
{
    long mtype;
    char mtext[1024];
};



int main()
{
    printf("Write\n");
    
    key_t key = ftok(".", 10);
    int msgid = msgget(key, IPC_CREAT | 0666);

    struct msgbuf data;
    memset(&data, 0, sizeof(data));
    data.mtype = 1;
    char text[1024];
    scanf("%s", text);
    strcpy(data.mtext, text);
    int res_write = msgsnd(msgid, &data, sizeof(data.mtext), 0);
    if (res_write == -1)
    {
        printf("error\n");
    }

    msgctl(msgid, IPC_RMID, NULL);
}